package com.equipment.training.web.interceptor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * ${DESCRIPTION}
 *
 * @author 杨凯
 * @create 2018-03-16 13:12
 **/
public class BasePathInterceptor extends HandlerInterceptorAdapter {

	private static Logger logger = LoggerFactory.getLogger(BasePathInterceptor.class);
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		String scheme = request.getScheme();
		String serverName = request.getServerName();
		int port = request.getServerPort();
		String path = request.getContextPath();
		String homeUrl = scheme + "://" + serverName + ":" + port + path;
		request.setAttribute("ctx", homeUrl);
		return true;
	}

}